package com.zwt.feign;

import com.zwt.configuration.FeignClientConfig;
import com.zwt.domain.TsPlatformUser;
import feign.Param;
import feign.RequestLine;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by zwt on 2018/8/24.
 */
@FeignClient(name = "provider-user",fallback = UserFeign.FeignClientFallBack.class,configuration = FeignClientConfig.class)
public interface UserFeign {

    @RequestMapping("providerUser/queryAll")
    public List<TsPlatformUser> queryAll();
    @RequestMapping("providerUser/queryOne/{id}")
    public TsPlatformUser queryOne(@PathVariable("id") Long id);
    @RequestMapping(value = "providerUser/selectOne")
    public TsPlatformUser selectOne(@RequestParam("id") Long id);


    /**
     * feign 回退类
     */
    @Component
     class FeignClientFallBack implements UserFeign{

        @Override
        public List<TsPlatformUser> queryAll() {
            return null;
        }

        @Override
        public TsPlatformUser queryOne(@PathVariable("id") Long id) {
            return null;
        }

        @Override
        public TsPlatformUser selectOne(Long id) {
            TsPlatformUser tsPlatformUser = new TsPlatformUser();
            tsPlatformUser.setId(-2l);
            tsPlatformUser.setNick("Feign使用Hystrix");
            return tsPlatformUser;
        }
    }
}
